package com.nbsaas.boot.customer.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.code.annotation.data.Dict;
import com.nbsaas.boot.code.annotation.data.DictItem;
import com.nbsaas.boot.code.annotation.data.DictKey;
import com.nbsaas.boot.common.data.entity.AbstractUser;
import com.nbsaas.boot.rest.filter.Operator;
import lombok.Data;
import org.hibernate.annotations.Comment;

import javax.persistence.*;
import java.util.Date;

@SearchBean(
        items = {
                @SearchItem(name = "addDateBegin",key = "addDate",label = "开始时间",classType = Date.class,operator = Operator.ge,show = false),
                @SearchItem(name = "addDateEnd",key = "addDate",label = "结束时间",classType = Date.class,operator = Operator.le,show = false),
                @SearchItem(name = "lastDateBegin",key = "lastDate",label = "开始时间",classType = Date.class,operator = Operator.ge,show = false),
                @SearchItem(name = "lastDateEnd",key = "lastDate",label = "结束时间",classType = Date.class,operator = Operator.le,show = false)
        }
)
@DiscriminatorValue("2")
@CreateByUser
@ComposeView
@Data
@FormAnnotation(title = "客户", model = "客户",showSelect = true)
@Entity
public class Customer extends AbstractUser {

    @Comment("客户名称")
    @SearchItem(name = "name",key = "name",label = "客户名称")
    @FormField(title = "客户名称", grid = true,required = true)
    @Column(length = 30)
    private String name;

    @Comment("昵称")
    @SearchItem(name = "nickName",label = "昵称",show = false)
    @FormField(title = "客户名称", grid = true)
    @Column(length = 30)
    private String nickName;


    @Comment("真实姓名")
    @SearchItem(name = "realName",key = "realName",label = "真实姓名",show = false)
    @FormField(title = "真实姓名", grid = true)
    @Column(length = 30)
    private String realName;

    @SearchItem(name = "phone", label = "联系电话")
    @Comment("联系电话")
    @FormField(title = "联系电话", grid = true)
    @Column(length = 30)
    private String phone;

    @FormField(title = "客户分组", grid = true,type = InputType.select,option = "customerGroup")
    @SearchItem(name = "customerGroup", label = "客户分组", operator = Operator.eq, classType = Long.class,type = InputType.select)
    @FieldName
    @FieldConvert
    @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    @ManyToOne(fetch = FetchType.LAZY)
    private CustomerGroup customerGroup;


    @FormField(title = "客户等级", grid = true,type = InputType.select,option = "customerLevel")
    @SearchItem(name = "customerLevel", label = "客户等级", operator = Operator.eq, classType = Long.class,type = InputType.select)
    @FieldName
    @FieldConvert
    @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    @ManyToOne(fetch = FetchType.LAZY)
    private CustomerLevel customerLevel;

    @Comment("身份证号码")
    private String idNumber;

    @Comment("身份证前面")
    private String frontIdCard;

    @Comment("身份证后面")
    private String backIdCard;


    @Comment("自拍照")
    private String selfFile;

    @Comment("性别")
    private String sex;

    @Comment("生日")
    private String birthDate;

    @Comment("地址")
    private String address;

    @DictKey("auditState")
    @Comment("审核状态 0待审核,1审核通过,2审核失败")
    @Dict(items = {
            @DictItem(value = 0, label = "待审核"),
            @DictItem(value = 1, label = "审核通过"),
            @DictItem(value = 2, label = "审核失败")
    })
    private Integer auditState;

    @Comment("备注")
    private String comment;

    @SearchItem(name = "shop", label = "来源店铺", operator = Operator.eq, classType = Long.class,show = false)
    @Comment("来源店铺")
    private Long shop;


    @FormField(title = "添加时间", grid = true, width = "11111", ignore = true)
    @Comment("添加时间")
    private Date addDate;

    @FormField(title = "最近时间",  ignore = true)
    @Comment("最近时间")
    private Date lastDate;

}
